package com.qf.ssm.controller;

import com.mysql.cj.Session;
import com.qf.ssm.po.Company;
import com.qf.ssm.qo.*;
import com.qf.ssm.result.ResponseResult;
import com.qf.ssm.result.ResultStatus;
import com.qf.ssm.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/*
 * 公司用户控制器
 * */
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;
    /*** 登录*/
    @PostMapping("/login")
    @ResponseBody
    public ResponseResult<Company> login(@RequestBody CompanyLoginQO companyLoginQO, HttpServletRequest request) {
        return ResponseResult.success(companyService.login(companyLoginQO,request));
    }

    /*** 注册*/
    @PostMapping("/register")
    public ResponseResult<Integer> register(@RequestBody CompanyRegisterQO companyRegisterQO,HttpServletRequest request,MultipartFile[] file) {
        return ResponseResult.success(companyService.register(companyRegisterQO,request,file));
    }

    /*** 修改密码*/
    @PostMapping("/edit/password")
    public ResponseResult<Integer> editPassword(@RequestBody CompanyUpdatePasswordQO companyUpdatePasswordQO, HttpServletRequest request){
        return ResponseResult.success(companyService.modifyPassword(companyUpdatePasswordQO,request));
    }

    /*** 找回密码*/
    @PostMapping("/find/password")
    public ResponseResult<Integer> findPassword(@RequestBody CompanyFindPasswordQO companyFindPasswordQO, HttpServletRequest request){
        return ResponseResult.success(companyService.modifyPasswordByEmail(companyFindPasswordQO,request));
    }

    /*** 查询用户信息*/
    @GetMapping("/info")
    public ResponseResult<Company> getCompanyInfo(HttpServletRequest request){
        return ResponseResult.success(companyService.queryCompanyInfo(request));
    }

    /*** 修改用户信息*/
    @PostMapping("/edit/company_info")
    public ResponseResult<Integer> editCompanyInfo(@RequestBody CompanyQO newCompany,HttpServletRequest request){
        return ResponseResult.success(companyService.modifyCompanyInfo(newCompany,request));
    }

    @GetMapping("/download/car_rental_license")
    public ResponseResult<File> downloadCarRentalLicense(HttpServletRequest request,HttpServletResponse response){
        return ResponseResult.success(companyService.queryCarRentalLicense(request,response));
    }

    /*** 退出登录*/
    @PostMapping("/login/out")
    public ResponseResult<Integer> loginOut(HttpServletRequest request){
       return ResponseResult.success(companyService.loginOut(request));
    }
}
